package com.example.controller;

import com.example.pojo.SaleChance;
import com.example.pojo.TCustomer;
import com.example.service.ITCustomerService;
import com.example.util.BaseController;
import com.example.vo.ResultInfo;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-24
 */
@RestController
@RequestMapping("/tCustomer")
@Api(tags = "",value = "")
@CrossOrigin(allowCredentials = "true")
public class TCustomerController extends BaseController {
    @Autowired
    private ITCustomerService itCustomerService;

    /**
     *分页
     * 模糊查询
     */
    @GetMapping("/pager")
    @ApiOperation(value = "获得客户信息管理分页信息")
    public PageInfo<TCustomer> displayPager(@RequestParam(defaultValue = "1")Integer pageNum,
                                            @RequestParam(defaultValue = "5")Integer pageSize,
                                            String name,
                                            String khno,
                                            String level,
                                            String area,
                                            String xyd,
                                            String fr,
                                            Integer state,
                                            Integer isValid){
        return itCustomerService.electByPager(pageNum,pageSize,name,khno,level,area,xyd,fr,state,isValid);
    }

    /**
     * 添加客户信息
     */
    @ApiOperation(value = "添加客户信息")
    @PostMapping("add")
    public ResultVo addCustomer(@RequestBody TCustomer tCustomer){
        return itCustomerService.addCustomer(tCustomer);
    }

    /**
     * 客户信息修改
     */
    @ApiOperation(value = "客户信息修改")
    @PutMapping("/update")
    public ResultInfo updateCustomer(@RequestBody TCustomer tCustomer){
        itCustomerService.updateCustomer(tCustomer);
        return success("客户信息数据修改成功！");
    }

    /**
     * 客户信息删除
     */
    @ApiOperation(value = "客户信息删除")
    @DeleteMapping("/{id}")
    public ResultVo deleteCustomer(@PathVariable("id") Integer id){
        TCustomer tCustomer = new TCustomer().setId(id).setIsValid(0);
        if(itCustomerService.removeById(tCustomer)){
            return ResultVo.ok("修改成功。");
        }
        return ResultVo.error("修改失败!");
    }

    /**
     * 查询所有
     */
    @GetMapping("")
    public List<TCustomer> displayTCustomerInfo(){
        return itCustomerService.selectAll();
    }

}
